package com.cosc716.restaurant.domain;

import java.util.ArrayList;

public class Table {
	
	private int tableNumber = -1;
	private int totalSeats = -1;
	private ArrayList<Customer> seatedCustomers = new ArrayList<Customer>();
	boolean hasOrdered = false;
	
	public Table(int tableNumber, int totalSeats) {
		this.tableNumber = tableNumber;
		this.totalSeats = totalSeats;
	}

	public int getTableNumber() {
		return tableNumber;
	}

	public int getTotalSeats() {
		return totalSeats;
	}

	public int getSeatsAvailable() {
		return totalSeats - seatedCustomers.size();
	}
	
	public boolean seatCustomer(Customer customer) {
		if(isFull()) {
			return false;
		}
		
		seatedCustomers.add(customer);
		
		return true;
	}
	
	public boolean seatCustomers(ArrayList<Customer> customers) {
		if(customers.size() > totalSeats) {
			return false;
		}
		
		seatedCustomers.addAll(customers);
		
		return true;
	}
	
	public boolean seatCustomerGroup(CustomerGroup group) {
		return this.seatCustomers(group.getCustomers());
	}
	
	public ArrayList<Customer> getSeatedCustomers() {
		return seatedCustomers;
	}
	
	public void clearTable() {
		seatedCustomers.clear();
		hasOrdered = false;
	}
	
	public boolean isEmtpy() {
		return seatedCustomers.isEmpty();
	}
	
	public boolean isFull() {
		return (seatedCustomers.size() == totalSeats);
	}
	
	public boolean isInUse() {
		return (seatedCustomers.size() > 0);
	}
	
	public void setOrderPlaced(boolean hasOrdered) {
		this.hasOrdered = hasOrdered;
	}
	
	public boolean isOrderPlaced() {
		return this.hasOrdered;
	}

	@Override
	public String toString() {
		return "Table [tableNumber=" + tableNumber + ", totalSeats="
				+ totalSeats + ", seatedCustomers=" + seatedCustomers
				+ ", hasOrdered=" + hasOrdered + "]";
	}
	
	
}
